﻿@model IEnumerable<Von.Web.Structs.SliderInfo>
@{
    ViewData["Title"] = "主页广告管理";
}
<h2>主页广告<a class="btn btn-link" onclick="NewSlider()">新建主页广告</a></h2>
<table id="SliderList" class="table">
    <thead>
        <tr>
            <th>类别</th>
            <th>名称</th>
            <th>有效期</th>
            <th>链接</th>
            <th>序号</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
        <tr>
            <td>@Html.DisplayFor(modelItem => item.Kind)</td>
            <td>@Html.DisplayFor(modelItem => item.Title)</td>
            <td>@Html.DisplayFor(modelItem => item.Validate)</td>
            <td>@Html.DisplayFor(modelItem => item.Linker)</td>
            <td>@Html.DisplayFor(modelItem => item.DisplayOrder)</td>
            <td>
                <input type="button" class="btn-link" onclick="EditSlider(this, '@item.ID')" value="编辑">
                <input type="button" class="btn-danger" onclick="DeleteSlider(this, '@item.ID')" value="删除">
            </td>
        </tr>
        }
    </tbody>
</table>
<!-- 模态框（Modal） -->
<div class="modal fade" id="SliderEditor" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true" data-mode="new">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="background-color:aquamarine;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ModalLabel">主页广告编辑</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <label for="Kind" class="input-group-addon column-prompt">类别</label>
                    <select id="Kind" class="form-control">
                        @foreach (var item in await (new Von.Web.Tasks.OptionTask()).GetOptValueArray("广告类别"))
                        {
                            <option>@item</option>
                        }
                    </select>
                </div>
                <div class="input-group">
                    <label for="Title" class="input-group-addon column-prompt">名称</label>
                    <input id="Title" class="form-control" />
                </div>
                <div class="input-group">
                    <label for="Import" class="input-group-addon column-prompt">引用资料</label>
                    <textarea id="Import" name="Import" style="height:380px;" class="form-control" placeholder="Head/BodyHeader/BodyTrailler/Footor,<importName>,<content>"></textarea>
                </div>
                <div class="form-group">
                    <label for="Content">网页内容</label>
                    <textarea id="Content" name="Content" style="height:380px;" class="form-control"></textarea>
                </div>
                <div class="input-group">
                    <label for="Validate" class="input-group-addon column-prompt">有效期</label>
                    <input id="Validate" type="date" class="form-control" />
                </div>
                <div class="input-group">
                    <label for="Linker" class="input-group-addon column-prompt">链接</label>
                    <input id="Linker" class="form-control" />
                </div>
                <div class="input-group">
                    <label for="DisplayOrder" class="input-group-addon column-prompt">显示序号</label>
                    <input id="DisplayOrder" type="number" class="form-control" />
                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="ID" />
                <div class="form-group">
                    <input value="保存" class="btn btn-default" onclick="SaveSlider()" />
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<script type="text/javascript">

    function NewSlider() {
        von.selectRow();
        von.editor.clear();
        von.editor.display("new");
    }
    function EditSlider(btn, id) {
        von.selectRow(btn);
        AjaxPostData("@Url.Ajax("GetBySlider")", { ID: id }, function (data) {
            von.editor.setData(data);
            contentEditor.setData(data["Content"]);
            von.editor.display("edit");
        });
    }
    function DeleteSlider(btn, id) {
        if (confirm('确定删除吗？')) {
            von.selectRow(btn);
            AjaxPostData('@Url.Ajax("DeleteSlider")', { 'ID': id }, function (result) { von.deleteRow(); });
        }
    }
    function CheckSlider(){
        var msg = "";
        if($("#Kind").val() == "") msg += "类型必须录入，不允许为空。";
        if($("#Title").val() == "") msg += "名称必须录入，不允许为空。";
        return msg;
    }
    function SaveSlider() {
        var msg = CheckSlider();
        if (msg != "") return SysWarning(msg);
        var data = {};
        von.editor.getData(data);
        data["Content"] = contentEditor.getData();
        if (von.editor.mode == "new") AjaxPostData("@Url.Ajax("AddSlider")", data, function (data) { von.appendRow(von.getHtml(data)); von.editor.close(); });
        else AjaxPostData("@Url.Ajax("EditSlider")", data, function (data) { von.replaceRow(von.getHtml(data)); von.editor.close(); });
    }
</script>
@Html.Partial("~/Views/Shared/_EditorScriptsPartial.cshtml")
@Html.Import(Von.Web.Html.EImportSection.BodyTrailler, "SliderInit",
    @<script>
         var von = VonGrid({
             app: "Slider",
             keyName: "ID",
             displayFields: ["Kind", "Title", "Validate", "Linker","DisplayOrder"],
             fields: ["ID", "Kind", "Title", "Import", "Content", "Validate", "Linker","DisplayOrder"]
         });
         var contentEditor = initHtmlDeveloperEditor("Content", "HtmlContent");
    </script>
)
